package health

import (
	"gitcode.com/G-YT/ANN/server/global"
	"gitcode.com/G-YT/ANN/server/model/common/response"
	"gitcode.com/G-YT/ANN/server/model/health"
	healthReq "gitcode.com/G-YT/ANN/server/model/health/request"
	"gitcode.com/G-YT/ANN/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type DiseaseApi struct {
}

var diseaseService = service.ServiceGroupApp.HealthServiceGroup.DiseaseService

// CreateDisease 創建Disease
// @Tags Disease
// @Summary 創建Disease
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.Disease true "創建Disease"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /disease/createDisease [post]
func (diseaseApi *DiseaseApi) CreateDisease(c *gin.Context) {
	var disease health.Disease
	err := c.ShouldBindJSON(&disease)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := diseaseService.CreateDisease(&disease); err != nil {
		global.GVA_LOG.Error("創建失敗!", zap.Error(err))
		response.FailWithMessage("創建失敗", c)
	} else {
		response.OkWithMessage("創建成功", c)
	}
}

// DeleteDisease 删除Disease
// @Tags Disease
// @Summary 删除Disease
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.Disease true "删除Disease"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /disease/deleteDisease [delete]
func (diseaseApi *DiseaseApi) DeleteDisease(c *gin.Context) {
	var disease health.Disease
	isDisease := c.Query("isDisease")
	err := c.ShouldBindJSON(&disease)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := diseaseService.DeleteDisease(disease, isDisease); err != nil {
		global.GVA_LOG.Error("删除失敗!", zap.Error(err))
		response.FailWithMessage("删除失敗", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteDiseaseByIds 批量删除Disease
// @Tags Disease
// @Summary 批量删除Disease
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Disease"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /disease/deleteDiseaseByIds [delete]
func (diseaseApi *DiseaseApi) DeleteDiseaseByIds(c *gin.Context) {
	//var IDS request.IdsReq
	//err := c.ShouldBindJSON(&IDS)
	//if err != nil {
	//	response.FailWithMessage(err.Error(), c)
	//	return
	//}
	//if err := diseaseService.DeleteDiseaseByIds(IDS); err != nil {
	//	global.GVA_LOG.Error("批量删除失敗!", zap.Error(err))
	//	response.FailWithMessage("批量删除失敗", c)
	//} else {
	//	response.OkWithMessage("批量删除成功", c)
	//}
}

// UpdateDisease 更新Disease
// @Tags Disease
// @Summary 更新Disease
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.Disease true "更新Disease"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /disease/updateDisease [put]
func (diseaseApi *DiseaseApi) UpdateDisease(c *gin.Context) {
	var disease health.Disease
	err := c.ShouldBindJSON(&disease)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := diseaseService.UpdateDisease(disease); err != nil {
		global.GVA_LOG.Error("更新失敗!", zap.Error(err))
		response.FailWithMessage("更新失敗", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindDisease 用id査詢Disease
// @Tags Disease
// @Summary 用id査詢Disease
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query health.Disease true "用id査詢Disease"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"査詢成功"}"
// @Router /disease/findDisease [get]
func (diseaseApi *DiseaseApi) FindDisease(c *gin.Context) {
	var disease health.Disease
	isDisease := c.Query("isDisease")
	err := c.ShouldBindQuery(&disease)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if redisease, err := diseaseService.GetDisease(disease.ID, isDisease); err != nil {
		global.GVA_LOG.Error("査詢失敗!", zap.Error(err))
		response.FailWithMessage("査詢失敗", c)
	} else {
		response.OkWithData(gin.H{"redisease": redisease}, c)
	}
}

// GetDiseaseList 分页獲取Disease列表
// @Tags Disease
// @Summary 分页獲取Disease列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query healthReq.DiseaseSearch true "分页獲取Disease列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /disease/getDiseaseList [get]
func (diseaseApi *DiseaseApi) GetDiseaseList(c *gin.Context) {
	var pageInfo healthReq.DiseaseSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := diseaseService.GetDiseaseInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}

func (diseaseApi *DiseaseApi) SetDiseaseGraphic(c *gin.Context) {
	var req healthReq.DiseaseGraphicReq
	err := c.ShouldBindJSON(&req)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := diseaseService.SetDiseaseGraphic(req); err != nil {
		global.GVA_LOG.Error("设置失敗!", zap.Error(err))
		response.FailWithMessage("设置失敗", c)
	} else {
		response.OkWithMessage("设置成功", c)
	}
}

func (diseaseApi *DiseaseApi) GetDiseaseGraphic(c *gin.Context) {
	disease_id := c.Query("disease_id")
	if res, err := diseaseService.GetDiseaseGraphic(disease_id); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithData(res, c)
	}
}
